/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <algorithm>

using namespace std;
/*-----------------------------------------------------------------------------*/
inline void File_Read() {
#ifndef MYLAB
	freopen("lcslength.in", "r", stdin);
	freopen("lcslength.out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
}

inline int get_str(char a[]) {
	int k = 0; char c = getchar();
	for(; (c < 'a' || c > 'z') && (c < 'A' || c > 'Z'); c = getchar());
	for(; c != '.'; c = getchar()) a[++k] = c;
	return k;
}

char a[5023], b[5023], f[5023][5023];

int main() {
	File_Read();
	int la = get_str(a);
	int lb = get_str(b);

	for(int i = 1; i <= la; i++) {
		for(int j = 1; j <= lb; j++) {
			if(a[i] == b[j]) f[i][j] = f[i - 1][j - 1] + 1;
			else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
		}
	}
	
//	for(int i = 1; i <= la; i++) cout <<b[i];
	printf("%d", f[la][lb]);


	return 0;
}

